import modelerStore from '@wf/components/bpmnjs/store/modeler';

// 设置流程图元素状态
export const setProcessStatus = (finishedSequenceFlowSet: any, finishedTaskSet: any, unfinishedTaskSet: any, subProcessList?: any) => {
  console.log('finishedSequenceFlowSet', finishedSequenceFlowSet, finishedTaskSet, unfinishedTaskSet, subProcessList);
  const modeler = modelerStore();
  const viewer = modeler.getModeler;
  const canvas = viewer.get('canvas');
  const elementRegistry = viewer.get('elementRegistry');
  if (Array.isArray(finishedSequenceFlowSet)) {
    finishedSequenceFlowSet.forEach((item) => {
      if (item != null) {
        const { activityId } = item;
        console.log('activityId', elementRegistry, activityId);
        const element = elementRegistry.get(activityId);
        console.log('找到节点', element);
        if (element) {
          canvas.addMarker(activityId, 'success');
          const conditionExpression = element.businessObject.conditionExpression;
          if (conditionExpression) {
            canvas.addMarker(activityId, 'condition-expression');
          }
        }
      }
    });
  }
  if (Array.isArray(finishedTaskSet)) {
    finishedTaskSet.forEach((item) => {
      if (item != null) {
        const { activityId } = item;
        const element = elementRegistry.get(activityId);
        if (element) canvas.addMarker(activityId, 'success');
      }
    });
  }
  if (Array.isArray(unfinishedTaskSet)) {
    unfinishedTaskSet.forEach((item) => {
      if (item != null) {
        const { activityId } = item;
        const element = elementRegistry.get(activityId);
        if (element) canvas.addMarker(activityId, 'current');
      }
    });
  }
};
